package com.ucode.model.cgms.form;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ucode.tool.validator.Mobile;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.time.LocalDateTime;

@Schema(description = "陪玩俱乐部社区系统 - 陪玩订单创建Form")
@Data
@EqualsAndHashCode
public class CgmsCompanionOrderCreateForm {

    @Schema(description = "服务商品编号", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "服务商品编号 不能为空")
    private Long productId;

    /**
     * 数量
     */
    @Schema(description = "数量", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "数量 不能为空")
    @Min(value = 1,message = "数量最小值为 1")
    private Integer quantity;

    /**
     * 预约类型
     */
    @Schema(description = "预约类型:1-尽快服务，2-指定时间", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "预约类型 不能为空")
    @Range(min = 1, max = 2, message = "预约类型范围在 1 到 2 之间")
    private Integer scheduledType;
    /**
     * 预约时间
     */
    @Schema(description = "预约时间，预约类型为指定时间时必填", requiredMode = RequiredMode.AUTO)
    private LocalDateTime scheduledTime;
    /**
     * 预约人
     */
    @Schema(description = "预约人", requiredMode = RequiredMode.REQUIRED)
    @NotBlank(message = "预约人 不能为空")
    @Size(max = 50, message = "预约人不能超过50个字符")
    private String scheduledName;
    /**
     * 预约联系电话
     */
    @Schema(description = "预约联系电话", requiredMode = RequiredMode.REQUIRED)
    @NotBlank(message = "预约联系电话 不能为空")
    @Size(max = 50, message = "预约联系电话不能超过 50 个字符")
    @Mobile
    private String scheduledContact;

    /**
     * 游戏类型: 1：端游，2：手游
     */
    @Schema(description = "游戏类型", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "游戏类型 不能为空")
    @Range(min = 1, max = 2, message = "游戏类型范围在 1 到 2 之间")
    private Integer gameType;
    /**
     * 游戏昵称
     */
    @Schema(description = "游戏昵称", requiredMode = RequiredMode.REQUIRED)
    @NotBlank(message = "游戏昵称 不能为空")
    @Size(max = 100, message = "游戏昵称不能超过 100 个字符")
    private String gameNickname;
    /**
     * 游戏ID
     */
    @Schema(description = "游戏ID", requiredMode = RequiredMode.REQUIRED)
    @NotBlank(message = "游戏ID 不能为空")
    @Size(max = 100, message = "游戏ID不能超过 100 个字符")
    private String gameId;
    /**
     * 订单备注
     */
    @Schema(description = "订单备注", requiredMode = RequiredMode.AUTO)
    @Size(max = 255, message = "订单备注不能超过 255 个字符")
    private String orderNote;

    @Schema(description = "支付应用编号", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "支付应用编号 不能为空")
    private Long payAppId;

    @AssertTrue(message = "请填写预约时间")
    public boolean isScheduledTimeCheck() {
        if(ObjectUtil.equal(2,this.scheduledType) && ObjUtil.isNull(this.scheduledTime)){
            return false;
        }
        return true;
    }


}
